package pe.com.hatunsol.hatun_android;

import android.content.Intent;
import android.content.res.Configuration;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.app.ActionBarDrawerToggle;
import android.util.DisplayMetrics;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;

import pe.com.hatunsol.hatun_android.R;

public class MainActivity extends ActionBarActivity {

    private ImageButton btRegContacto, btAfiliados, btRegVentas, btMaps, btConsultarCredito,btListarVenta;

    private DrawerLayout mDrawerLayout;
    private ListView mLvMenu;
    private ActionBarDrawerToggle mActionBarDrawerToggle;
    private LinearLayout llMenu;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Primer commit Vladimir
        setContentView(R.layout.activity_main);

//Configurar Menu con Drawer
        llMenu = (LinearLayout) findViewById(R.id.llMenu);
        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
        DrawerLayout.LayoutParams dllp = (DrawerLayout.LayoutParams) llMenu.getLayoutParams();
        dllp.width = displayMetrics.widthPixels - getResources().getDimensionPixelOffset(R.dimen.lvmenu_marginright);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
        mActionBarDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, mDrawerLayout, R.string.app_name, R.string.app_name) {
            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
            }
        };
        mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);


        btRegContacto = (ImageButton) findViewById(R.id.btRegContacto);
        btAfiliados = (ImageButton) findViewById(R.id.btAfiliados);
        btRegVentas = (ImageButton) findViewById(R.id.btRegVentas);
        btMaps = (ImageButton) findViewById(R.id.btMaps);
        btConsultarCredito = (ImageButton) findViewById(R.id.btConsultarCredito);
        btListarVenta = (ImageButton) findViewById(R.id.btListarVenta);
        btRegContacto.setOnClickListener(btRegContactoOnClickListener);
        btAfiliados.setOnClickListener(btAfiliadosOnClickListener);
        btMaps.setOnClickListener(btMapsOnClickListener);

        btRegVentas.setOnClickListener(registrarventa);

        btConsultarCredito.setOnClickListener(consultarcredito);


        btListarVenta.setOnClickListener(btListarventaOnClickListener);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (mActionBarDrawerToggle.onOptionsItemSelected(item))
            return true;
        else
            return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mActionBarDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mActionBarDrawerToggle.onConfigurationChanged(newConfig);
    }

    View.OnClickListener btMapsOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, EstablecimientosCercanos.class);
            startActivity(intent);
        }
    };

    View.OnClickListener btListarventaOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ListarVenta.class);
            startActivity(intent);
        }
    };

    View.OnClickListener btRegContactoOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, RegContactoActivity.class);
            startActivity(intent);
        }
    };

    View.OnClickListener btAfiliadosOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ListaEstablecimientoActivity.class);
            startActivity(intent);
        }
    };

    View.OnClickListener registrarventa = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intento = new Intent(MainActivity.this, RegVentaActivity.class);
            startActivity(intento);
        }
    };


    View.OnClickListener consultarcredito = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intentsito = new Intent(MainActivity.this, ConsultarCredito.class);
            startActivity(intentsito);
        }
    };

}
